import { APILX } from '@/api/requestLx'
import { map, mapTree } from 'xe-utils/methods'
import { categoryGetTree, getDictModel } from '@/api/goodsManagement'
export let columns = [
  {
    title: '物品编号',
    dataIndex: 'goodsCode',
    ellipsis: true,
    width: 200,
    searchIndex: 'goodsCode',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsCode',
    },
  },
  {
    title: '物品名称',
    dataIndex: 'goodsName',
    ellipsis: true,
    width: 200,
    searchIndex: 'goodsName',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsName',
    },
  },
  {
    title: '规格',
    dataIndex: 'spec',
    width: 180,
    ellipsis: true,
    scopedSlots: {
      customRender: 'spec',
    },
  },
  {
    title: '分类',
    dataIndex: 'categoryText',
    ellipsis: true,
    width: 180,
    searchIndex: 'category',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdownTree',
      filterIcon: 'dateIcon',
      customRender: 'category',
    },
  },
  {
    title: '类型',
    dataIndex: 'typeText',
    ellipsis: true,
    width: 180,
    searchIndex: 'type',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'dateIcon',
      customRender: 'type',
    },
  },
  {
    title: '物品数量',
    dataIndex: 'goodsNum',
    width: 180,
    ellipsis: true,
    scopedSlots: {
      customRender: 'goodsNum',
    },
  },
  {
    fixed: 'right',
    title: '操作',
    align: 'left',
    dataIndex: 'actions',
    width: 150,
    scopedSlots: { customRender: 'actions' },
  },
]
export let allColumn = [
  {
    title: '物品编号',
    dataIndex: 'goodsCode',
    ellipsis: true,
    width: 200,
    searchIndex: 'goodsCode',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsCode',
    },
  },
  {
    title: '物品名称',
    dataIndex: 'goodsName',
    ellipsis: true,
    width: 200,
    searchIndex: 'goodsName',
    scopedSlots: {
      filterDropdown: 'searchDropdown',
      filterIcon: 'searchIcon',
      customRender: 'goodsName',
    },
  },
  {
    title: '规格',
    dataIndex: 'spec',
    width: 180,
    ellipsis: true,
    scopedSlots: {
      customRender: 'spec',
    },
  },
  {
    title: '分类',
    dataIndex: 'categoryText',
    ellipsis: true,
    width: 180,
    searchIndex: 'category',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdownTree',
      filterIcon: 'dateIcon',
      customRender: 'category',
    },
  },
  {
    title: '类型',
    dataIndex: 'typeText',
    ellipsis: true,
    width: 180,
    searchIndex: 'type',
    options: [],
    scopedSlots: {
      filterDropdown: 'selectDropdown',
      filterIcon: 'dateIcon',
      customRender: 'type',
    },
  },
  {
    title: '物品数量',
    dataIndex: 'goodsNum',
    width: 180,
    ellipsis: true,
    scopedSlots: {
      customRender: 'goodsNum',
    },
  },
]
export function getTypeList() {
  let parametersType = { dictCode: 'wms_goods_type' }
  getDictModel(parametersType).then((res) => {
    if (res.success) {
      let newArr = res.result.map((item) => {
        return {
          label: item.title,
          key: item.value,
        }
      })
      columns[4].options = newArr
      allColumn[4].options = newArr
    } else {
      this.$antdMessage.warning(res.message)
    }
  })

  // 取分类树
  categoryGetTree({ code: 'B05' }).then((res) => {
    let arr = res.result
    arr.map((item) => {
      if (item.children.length > 0) {
        item.disabled = true
        ;(function bianli(e = item) {
          e.children.forEach((item) => {
            if (item.children.length > 0) {
              item.disabled = true
              bianli(item)
            }
          })
        })()
      }
    })
    columns[3].options = arr
    allColumn[3].options = arr
  })

  // APILX.wmsWarehouseGetTypeList().then((res) => {
  //   if (res.code == 200) {
  //     let newArrStatus = res.result.map((item) => {
  //       return {
  //         label: item.title,
  //         key: item.value,
  //       }
  //     })
  //     columns[4].options = newArrStatus
  //     allColumn[4].options = newArrStatus
  //   }
  // })
}
